<?php
#
# 一个通过jquery的ajax提交的例子
# 关键点 //$(window.frames[0].document).find("#ModeCheck").click();
#

?>
<script type="text/javascript" src="common/scripts/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#saveButton").click(function(){

		//check_frm();
		//alert($(window.frames["iframe1"].document).find('#gently_editor').val());

				//$("#ModeCheck").click();
				//$(window.frames[0].document).find("#ModeCheck").click();
		//alert($(window.frames[0].document).find('#editor_body_textarea').val());



		if (checkForm()){
			$('#form1').append("<img id='loadimg' src='common/img/admin/loading.gif' />");
			$(window.frames[0].document).find("#ModeCheck").click();
			$.ajax({
				type:"POST",
				url: "index.php?module=buy",		data:$('#form1').serialize()+'&specify='+$(window.frames[0].document).find('#editor_body_textarea').val(),
				success:function(msg){
					var op = $('#form1 #op').val();
					if (op == 'add'){
						if (msg == 'ok'){$("#loadimg").remove();alert('添加成功！');
						document.location.href= "index.php?module=buy";}
						else{$("#loadimg").remove();alert('出错，请重新添加');
						}

					}else if (op == 'edit'){
						if(msg == 'ok'){$("#loadimg").remove();alert('修改成功！');
						document.location.href= "index.php?module=buy";
						}
						else{alert('出错，请重新编辑！');}
					}
				}
			});
		}
    });
	checkForm = function (){
		//if ($.trim($('#orderId').val()) == ''){alert($('#orderId').attr('error'));return false;}
		//if ($.trim($('#name').val()) == ''){alert($('#name').attr('error'));return false;}
		//if ($.trim($('#url').val()) == ''){alert($('#url').attr('error'));return false;}
		return true;
	};

	/*
	check_frm = function (){

		var editor_content='';

		if($(document.frames[0]).find("input[name='editor_body_textarea']").css("display")=='none')
		{//设计模式
			editor_content=document.frames[0].frames[0].contentWindow.document.body.innerHTML;
		}
		else
		{
			editor_content=$(document.frames[0].frames[0]).find("input[name='editor_body_textarea']").val();
		}
		if(editor_content==''){
			alert('请在编辑器输入内容！');
			return false;
		}
		else{//return true;
		alert(editor_content);
		}
			/*if(document.frames[0].$('editor_body_textarea').style.display=='none')
		{//设计模式
			editor_content=document.frames[0].frames[0].contentWindow.document.body.innerHTML);
		}
		else
		{
			editor_content=document.frames[0].$('editor_body_textarea').value);
		}
		if(editor_content==''){
			alert('请在编辑器输入内容！');
			return false;
		}
		else{return true;}
	}
	*/

});
</script>
<body>
<div id="man_zone">
<form name="form1" id="form1">
<table border="0" cellpadding="3" cellspacing="1" class="tableAdd">
<tr><td colspan="2" class="title">供求信息</td></tr>
<tr><th>供/求</th><td><?php echo $pForm->radioMake('buyType', $aBuyType, '0', $aBuy['buyType'], ''); ?></td></tr>
<tr><th>商品名称</th><td><?php echo $pForm->getForm('text', 'name', stripslashes($aBuy['name']), ' error="请填写商品名称！" '); ?></td></tr>
<tr><th>公司名称</th><td><?php echo $pForm->getForm('text', 'companyName', $aBuy['companyName'], ' error="请填写公司名称！" '); ?></td></tr>
<tr><th>发布状态</th><td><?php echo $pForm->radioMake('status', $aBuyStatus, '0', $aBuy['status'], ''); ?></td></tr>
<tr><th>详细信息</th>
	<td>
		<?php

		require_once ROOT.'lib/plugin/SinaEditor/sinaEditor.class.php';

		//print_r($_POST);
		//print_r($_GET);
		/*
		extract($_POST);
		extract($_GET);
		unset($_POST,$_GET);
		if(isset($act)){
		$act=='subok' && die("提交的内容是：<br>".htmlspecialchars($gently_editor));
		}
		*/

		$editor=new sinaEditor('gently_editor');
		$editor->Value=$aBuy['specify'];
		$editor->BasePath='lib/plugin/SinaEditor';
		$editor->Height=500;
		$editor->Width=700;
		$editor->AutoSave=false;

		$editor->Create();
		?>
	</td>
</tr>
<tr><td colspan="2" class="tdSave"><?php echo $pForm->getForm('button', 'saveButton', ' 提交 ', ''); ?></td></tr>
</table>
<?php echo $pForm->getForm('hidden', 'op', $op, ''); ?>
<?php echo $pForm->getForm('hidden', 'cId', $_GET['id'], ''); ?>
</form>
</div>
</body>
</html>
